﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class RoundContainerForm : ItemFormTemplate
    {
        public RoundContainerForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件\\RoundContainerForm\\RoundContainerForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.BorderThickness = 1;
            this.demo_control.TrapeziformCutEnabled = false;
            this.demo_control.RoundSize = new RoundCorner(10);

            this.trapeziformCutEnabled_toggleSwitch.IsOn = this.demo_control.TrapeziformCutEnabled;
            this.trapeziformCutEnabled_toggleSwitch.Toggled += this.TrapeziformCutEnabled_toggleSwitch_Toggled;

            this.borderThickness_label.Text = this.demo_control.BorderThickness.ToString();
            this.borderThickness_trackBarPlus.Value = this.demo_control.BorderThickness;
            this.borderThickness_trackBarPlus.ValueChanged += this.BorderThickness_trackBarPlus_ValueChanged;

            this.roundLeftTop_label.Text = this.demo_control.RoundSize.LeftTop.ToString();
            this.roundLeftTop_trackBarPlus.Value = this.demo_control.RoundSize.LeftTop;
            this.roundLeftTop_trackBarPlus.ValueChanged += this.RoundLeftTop_trackBarPlus_ValueChanged;

            this.roundRightTop_label.Text = this.demo_control.RoundSize.RightTop.ToString();
            this.roundRightTop_trackBarPlus.Value = this.demo_control.RoundSize.RightTop;
            this.roundRightTop_trackBarPlus.ValueChanged += this.RoundRightTop_trackBarPlus_ValueChanged;

            this.roundRightBottom_label.Text = this.demo_control.RoundSize.RightBottom.ToString();
            this.roundRightBottom_trackBarPlus.Value = this.demo_control.RoundSize.RightBottom;
            this.roundRightBottom_trackBarPlus.ValueChanged += this.RoundRightBottom_trackBarPlus_ValueChanged;

            this.roundLeftBottom_label.Text = this.demo_control.RoundSize.LeftBottom.ToString();
            this.roundLeftBottom_trackBarPlus.Value = this.demo_control.RoundSize.LeftBottom;
            this.roundLeftBottom_trackBarPlus.ValueChanged += this.RoundLeftBottom_trackBarPlus_ValueChanged;


        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void TrapeziformCutEnabled_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.TrapeziformCutEnabled = control.IsOn;
        }

        private void BorderThickness_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.BorderThickness = (int)control.Value;
            this.borderThickness_label.Text = this.demo_control.BorderThickness.ToString();
        }

        private void RoundLeftTop_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.RoundSize = new RoundCorner((int)control.Value, this.demo_control.RoundSize.RightTop, this.demo_control.RoundSize.RightBottom, this.demo_control.RoundSize.LeftBottom);
            this.roundLeftTop_label.Text = this.demo_control.RoundSize.LeftTop.ToString();
        }

        private void RoundRightTop_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.RoundSize = new RoundCorner(this.demo_control.RoundSize.LeftTop, (int)control.Value, this.demo_control.RoundSize.RightBottom, this.demo_control.RoundSize.LeftBottom);
            this.roundRightTop_label.Text = this.demo_control.RoundSize.RightTop.ToString();
        }

        private void RoundRightBottom_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.RoundSize = new RoundCorner(this.demo_control.RoundSize.LeftTop, this.demo_control.RoundSize.RightTop, (int)control.Value, this.demo_control.RoundSize.LeftBottom);
            this.roundRightBottom_label.Text = this.demo_control.RoundSize.RightBottom.ToString();
        }

        private void RoundLeftBottom_trackBarPlus_ValueChanged(object sender, EventArgs e)
        {
            TrackBarPlus control = (TrackBarPlus)sender;
            this.demo_control.RoundSize = new RoundCorner(this.demo_control.RoundSize.LeftTop, this.demo_control.RoundSize.RightTop, this.demo_control.RoundSize.RightBottom, (int)control.Value);
            this.roundLeftBottom_label.Text = this.demo_control.RoundSize.LeftBottom.ToString();
        }
        #endregion

    }
}
